﻿package mortal.game.view.common.guide.view
{
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.greensock.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.common.font.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.guide.data.*;

    public class AutoGuideTweenTipsItem extends Object
    {
        private var _txt:GTextFiled;
        private var _data:AutoGuideData;
        private var _tween:TweenMax;
        private var tweenY:int;
        private var tweenAlpha:Number;
        private var time1:Number;
        private var time2:Number;
        private var _callback:Function;

        public function AutoGuideTweenTipsItem()
        {
            return;
        }// end function

        public function get data() : AutoGuideData
        {
            return this._data;
        }// end function

        public function guide(param1:AutoGuideData, param2:Function) : void
        {
            var _loc_3:Array = null;
            var _loc_4:Array = null;
            var _loc_7:Array = null;
            var _loc_8:DisplayObject = null;
            var _loc_9:String = null;
            var _loc_10:String = null;
            var _loc_11:Window = null;
            var _loc_12:Point = null;
            this._callback = param2;
            if (this._tween != null)
            {
                this._tween.kill();
            }
            if (this._txt != null)
            {
                this._txt.dispose(true);
            }
            this._data = param1;
            _loc_3 = String(param1.guideTypeValue).split(";");
            _loc_4 = String(param1.clickChildName).split(";");
            if (param1.subTypeValue == null || param1.subTypeValue == "")
            {
                this.tweenY = 20;
                this.tweenAlpha = 0.4;
                this.time1 = 0.7;
                this.time2 = 0.7;
            }
            else
            {
                _loc_7 = String(param1.subTypeValue).split(";");
                this.tweenY = int(_loc_7[0]);
                this.tweenAlpha = Number(_loc_7[1]);
                this.time1 = Number(_loc_7[2]);
                this.time2 = Number(_loc_7[3]);
            }
            var _loc_5:* = GlobalStyle.textFormatLv;
            _loc_5.size = int(_loc_3[0]);
            _loc_5.color = uint(_loc_3[1]);
            _loc_5.font = FontUtil.lishuName;
            this._txt = UIFactory.gTextField("", 0, 0, 600, 100, null, _loc_5);
            this._txt.mouseEnabled = false;
            this._txt.multiline = true;
            this._txt.wordWrap = true;
            this._txt.htmlText = HTMLUtil.getHtmlByComp(_loc_3[2]);
            this._txt.x = int(_loc_4[0]);
            this._txt.y = int(_loc_4[1]);
            if (_loc_4.length > 2 && _loc_4[2] == "middleStage")
            {
                this._txt.x = int(_loc_4[0]) + Global.stage.stageWidth / 2;
                this._txt.y = int(_loc_4[1]) + Global.stage.stageHeight / 2;
                LayerManager.highestLayer.addChild(this._txt);
            }
            if (_loc_4.length > 2 && _loc_4[2] == "rightDownStage")
            {
                this._txt.x = int(_loc_4[0]) + Global.stage.stageWidth;
                this._txt.y = int(_loc_4[1]) + Global.stage.stageHeight;
                LayerManager.highestLayer.addChild(this._txt);
            }
            else if (_loc_4.length > 2)
            {
                _loc_9 = _loc_4[2];
                if (_loc_4.length >= 4)
                {
                    _loc_10 = _loc_4[3];
                    _loc_11 = DisplayUtil.getChildByPropety(LayerManager.windowLayer, "winTitleName", _loc_10) as Window;
                    if (_loc_11 == null)
                    {
                        _loc_11 = DisplayUtil.getChildByPropety(LayerManager.windowLayer3D, "winTitleName", _loc_10) as Window;
                    }
                    if (_loc_11 != null)
                    {
                        _loc_8 = DisplayUtil.getChildByPropety(_loc_11, "name", _loc_9);
                        if (_loc_8 == null)
                        {
                            _loc_8 = DisplayUtil.getChildByPropety(_loc_11.contentTopOf3DSprite, "name", _loc_9);
                        }
                    }
                }
                else
                {
                    _loc_8 = DisplayUtil.getChildByPropety(LayerManager.windowLayer, "name", _loc_9);
                    if (_loc_8 == null)
                    {
                        _loc_8 = DisplayUtil.getChildByPropety(LayerManager.windowLayer3D, "name", _loc_9);
                    }
                    if (_loc_8 == null)
                    {
                        _loc_8 = DisplayUtil.getChildByPropety(LayerManager.uiLayer, "name", _loc_9);
                    }
                    if (_loc_8 == null)
                    {
                        _loc_8 = DisplayUtil.getChildByPropety(LayerManager.highestLayer, "name", _loc_9);
                    }
                }
                if (_loc_8 != null)
                {
                    this._txt.x = int(_loc_4[0]) + _loc_8.x;
                    this._txt.y = int(_loc_4[1]) + _loc_8.y;
                    _loc_12 = _loc_8.parent.localToGlobal(GameConst.yellowPoint);
                    this._txt.x = this._txt.x + _loc_12.x;
                    this._txt.y = this._txt.y + _loc_12.y;
                    LayerManager.highestLayer.addChild(this._txt);
                }
            }
            else
            {
                LayerManager.highestLayer.addChild(this._txt);
            }
            if (param1.rollingTips != null && param1.rollingTips != "")
            {
                this._txt.htmlText = _loc_3[2] + AutoGuideCache.instance[param1.rollingTips].toString();
            }
            var _loc_6:* = this._txt.y - this.tweenY;
            this._txt.alpha = this.tweenAlpha;
            this._tween = TweenMax.to(this._txt, this.time1, {alpha:1, y:_loc_6, onComplete:this.tweenComplete1});
            return;
        }// end function

        private function tweenComplete1() : void
        {
            var _loc_1:* = this._txt.y - this.tweenY;
            this._tween = TweenMax.to(this._txt, this.time2, {alpha:this.tweenAlpha, y:_loc_1, onComplete:this.tweenCompleted});
            return;
        }// end function

        public function stop() : void
        {
            this.tweenCompleted();
            return;
        }// end function

        private function tweenCompleted() : void
        {
            if (this._txt != null)
            {
                this._txt.dispose(true);
                this._txt = null;
            }
            if (this._tween != null)
            {
                this._tween.kill();
                this._tween = null;
            }
            if (this._callback != null)
            {
                this._callback.apply(null, [this]);
                this._callback = null;
            }
            return;
        }// end function

    }
}
